<?php
/**
 * Create a new ressource
 * @author Xavier VILAIN
 *
 */
echo "testf";
use Fox\Html\Screen;
use Hive\School;
$ecran = new Screen("HDR","create");
$block = Xview::instance()->component("ressource", "header");
$block->id("AddRessource");
$ecran->add($block);
$blkcon = new Fox\Html\Block("BCON","Information Contact");

if($ecran->submitted())
{
	$inputs = $ecran->get();
	if(!$screen->errors())
	{
		try {
			// Check if the school already exist
			if(!empty($inputs['school']))
			{
				$school = School::lookup($inputs['school']);
				if(!$school)
				{
					$school = new School();
					$school->setFields(array("sch_name" => $inputs['school']));
					$school->create();
				}
				$inputs['schoolid'] = $school->getId();
			}
			$ressource = new  Hive\Ressource();
			$ressource->setFields($inputs);

			$ressource->create();
			$id = $ressource->getId();
			Xview::instance()->redirect("?mod=ressource&act=update&ressourceid=$id");
		}
		catch(Fox\Object\Exception\Save $e)
		{
			Fox\Message::Error($e->getMessage());
		}
	}
}
echo $ecran->Display();